;(() => {
    const app = new Vue({
        el: '#login',
        data: {
            user: {
                username: "",
                email: "",
                password: ""
            },
            username: [],
            password: [],
            email: []
        },
        methods: {
            async handleSubmit() {
                try {
                    this.username = [];
                    this.email = [];
                    this.password = [];
                    await $.post('api/users/', {user: this.user}, () => {
                        console.log(`发送成功！！`);
                    }, 'json')
                    window.location.href = "/"
                } catch (err) {
                    if (err.status === 400) {
                        const {errors} = err.responseJSON;
                        errors.forEach((value) => {
                            switch (value.param) {
                                case "user.username":
                                    this.username.push(value);
                                    break;
                                case "user.password":
                                    this.password.push(value);
                                    break;
                                case "user.email":
                                    this.email.push(value);
                                    break;
                                default:
                                    break;
                            }
                        })
                    }
                }
            }
        }
    })
})();